package com.hruiworks.campusgroup.quartz.factory.job;

import com.alibaba.fastjson2.JSON;
import com.hruiworks.campusgroup.manager.entity.GroupFullInfo;
import com.hruiworks.campusgroup.pojo.entity.Activity;
import com.hruiworks.campusgroup.pojo.entity.Group;
import com.hruiworks.campusgroup.pojo.entity.User;
import com.hruiworks.campusgroup.quartz.common.QuartzGroupUtils;
import com.hruiworks.campusgroup.quartz.common.QuartzNameUtils;
import com.hruiworks.campusgroup.quartz.job.GroupStartNoticeJob;
import org.quartz.JobDetail;

import static com.hruiworks.campusgroup.quartz.constants.JobDataMapKey.GROUP_MESSAGE;
import static com.hruiworks.campusgroup.quartz.constants.JobDataMapKey.USER_MESSAGE;
import static org.quartz.JobBuilder.newJob;

public class GroupStartNoticeJobFactory {

    /**
     * 创建活动开始提前通知任务
     *
     * @param group 所属团队
     * @return 返回quartz任务
     */
    public JobDetail getJob(User user, Group group, Activity activity) {
        String jobGroup = QuartzGroupUtils.groupStartNotice(user);
        String jobName = QuartzNameUtils.groupStartNotice(group);
        GroupFullInfo groupFullInfo = new GroupFullInfo();
        groupFullInfo.setGroup(group);
        groupFullInfo.setActivity(activity);
        String groupMessage = JSON.toJSONString(groupFullInfo);
        String userMessage = JSON.toJSONString(user);
        return newJob(GroupStartNoticeJob.class)
                .withIdentity(jobName, jobGroup)
                .usingJobData(GROUP_MESSAGE, groupMessage)
                .usingJobData(USER_MESSAGE, userMessage)
                .build();
    }

}
